<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(90, 194, 255, 1);
        }

        .mall-bg {
            background-color: #f5f5f5;
        }

        .vueApp {
            padding-bottom: 42px;
        }

        .container {
            position: relative;
            margin: 15px;
            padding: 15px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 1px 8px 0px rgba(0, 0, 0, 0.02);
            border-radius: 8px;
            overflow: inherit;
        }

        .name {
            font-size: 14px;
            font-weight: 400;
            color: rgba(63, 64, 70, 1);
            margin-right: 10px;
        }

        .phone {
            font-size: 14px;
            font-weight: 400;
            color: rgba(161, 165, 177, 1);
            margin-right: 10px;
        }

        .mark {
            width: 39px;
            text-align: center;
            background: #FD9B43;
            color: #fff;
            font-size: 12px;
        }

        .address {
            width: 100%;
            font-size: 14px;
            font-weight: 400;
            color: rgba(127, 129, 141, 1);
            line-height: 14px;
        }

        .address p {
            margin-top: 8px;
        }

        .long-box {
            z-index: 100;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            width: 210px;
            height: 42px;
            overflow: inherit;
        }

        .top {
            top: -42px;
        }

        .bottom {
            bottom: -49px;
        }

        .bottom img {
            position: absolute;
            top: -7px;
            left: 50%;
            width: 14px;
            height: 7px;
            transform: translateX(-50%) rotate(180deg);
        }

        .top img {
            position: absolute;
            bottom: 0;
            left: 50%;
            width: 14px;
            height: 7px;
            transform: translateX(-50%);
        }

        .long-btn {
            border-radius: 6px;
        }

        .long-btn p {
            position: relative;
            background-color: rgba(35, 35, 35, 0.91);
            color: #fff;
            text-align: center;
            font-size: 12px;
            line-height: 35px;
            height: 35px;
            font-weight: 100;
            width: 60px;
        }

        .long-btn p.center {
            width: 90px;
        }

        .long-btn p.disabled {
            color: rgba(255, 255, 255, 0.5);
        }

        .long-btn p.center::before {
            content: ' ';
            position: absolute;
            top: 50%;
            left: 0;
            height: 24px;
            background-color: #fff;
            width: 1px;
            transform: scaleX(0.5) translateY(-50%);
        }

        .long-btn p.center::after {
            content: ' ';
            position: absolute;
            top: 50%;
            right: 0;
            height: 24px;
            background-color: #fff;
            width: 1px;
            transform: scaleX(0.5) translateY(-50%);
        }

        .radio {
            width: 22px;
            min-width: 22px;
            height: 22px;
            margin-right: 15px;
            background-image: url("../../image/ui/radio.png");
            background-size: 100% 100%;
        }

        .checked {
            width: 22px;
            min-width: 22px;
            height: 22px;
            margin-right: 15px;
            background-image: url("../../image/ui/checked.png");
            background-size: 100% 100%;
        }

        .mall-btn {
            margin: 20px 15px 0 15px;
            height: 44px;
            background-color: #5AC2FF;
            border-radius:100px;
            font-size:16px;
            font-weight:500;
            color:rgba(255,255,255,1);
            line-height:22px;
            letter-spacing:1px;
        }

        .tips--white {
            margin-top: 10.5rem;
            margin-bottom: 10.5rem;
            color: #fff;
            font-size: 14px;
            font-weight: 400;
        }

        .tips--black {
            margin-top: 10.5rem;
            margin-bottom: 10.5rem;
            color: #000;
            font-size: 14px;
            font-weight: 400;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div v-if="listData.length > 0">
            <div class="container" data-flex="cross:center" :data-index="index" ontouchstart="gtouchstart(this)" ontouchmove="gtouchmove()"
                ontouchend="gtouchend()" v-for="item,index in listData">
                <div @click="handleSelect(index)" :class="checked === index ? 'checked' : 'radio'" v-if="isSelectAddress"></div>
                <div data-flex-box="1">
                    <div data-flex="cross:center">
                        <div class="name">{{ item.name }}</div>
                        <div class="phone">{{ item.phoneNumber }}</div>
                        <div class="mark" v-if="item.defaultStatus == 1">默认</div>
                    </div>
                    <div class="address">
                        <p>{{ item.schoolAddress }}</p>
                        <p>{{ item.detailAddress }}</p>
                    </div>
                </div>
                <div v-if="item.sel" :class="index === 0 ? 'long-box bottom' : 'long-box top'">
                    <div class="long-btn" data-flex="">
                        <p @click="deleteFn(item)">删除</p>
                        <p :class="item.defaultStatus == 1 ? 'center disabled' : 'center'"
                            @click="item.defaultStatus == 1 ? '' : setDefault(item)">设置为默认</p>
                        <p @click="editFn(item)">编辑</p>
                    </div>
                    <img src="../../image/course/longpress.png" alt="">
                </div>
            </div>
        </div>
        <div v-else-if="isLoad" :class="isSelectAddress ? 'tips--black' : 'tips--white'" data-flex="main:center cross:center">
            暂时没有更多数据哦
        </div>
        <div class="mall-btn" v-if="isSelectAddress" onclick="headerFn()" data-flex="main:center cross:center">新建地址</div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var pageParam = {};
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        fnInit();
    };

    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                checked: -1,
                pageNo: 1,
                pageSize: 10,
                isLoad: false,
                listData: [],
                isSelectAddress: pageParam.isSelectAddress || false
            }
        });
        load();
        if(vm.isSelectAddress) {
            document.body.className = 'mall-bg';
        }
    }

    // 选中地址
    function handleSelect(index) {
        vm.checked = index;
    }

    // 导航栏确认选中地址
    function handleHeaderConfirm() {
        if(vm.checked == -1) {
            fnToast('请先选择地址');
            return;
        }
        var item = vm.listData[vm.checked]; // 选中的地址的索引
        api.execScript({
            name: pageParam.winName,
            script: 'handleSelectAdress('+ JSON.stringify(item) +')'
        });
        api.closeWin();
    }

    function load() {
        getPageData('headerRefreshing');
        fnAddHeaderRefreshingEvent(function () { //设置下拉刷新
            getPageData('headerRefreshing');
        });

        fnAddFooterLoadingEvent(function () { // 设置上拉加载
            getPageData('load');
        });
    }

    // 获取页面数据
    function getPageData(sign) {
        if (sign == 'headerRefreshing') {
            vm.pageNo = 1;
        } else {
            vm.pageNo++;
        }
        var url = 'my/findMyAddressList';
        var params = {
            "pageNo": vm.pageNo,
            "pageSize": vm.pageSize
        };
        var callback = function (data) {
            if (vm.pageNo == '1') {
                vm.listData = [];
            }
            var listData = data.listData;
            for (var i = 0; i < listData.length; i++) {
                var item = listData[i];
            }
            api.refreshHeaderLoadDone();
            vm.listData = vm.listData.concat(data.listData);
            vm.isLoad = true;
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }

    function headerFn() {
        fnOpenPublicWin('新增收货地址', 'teacher/edit_address', {
            winName: api.winName,
            frmName: api.frameName
        });
    }

    var timeOutEvent = 0; //定时器
    var longIndex = -1;
    //开始按
    function gtouchstart(el) {
        debugger
        timeOutEvent = setTimeout(function () {
            vm.listData = setPropertyInArray(vm.listData, 'sel', false);
            longIndex = el.dataset.index;
            longPress();
        }, 1000); //这里设置定时器，定义长按500毫秒触发长按事件，时间可以自己改，个人感觉500毫秒非常合适
        return false;
    };
    //手释放，如果在500毫秒内就释放，则取消长按事件，此时可以执行onclick应该执行的事件
    function gtouchend() {
        clearTimeout(timeOutEvent); //清除定时器
        if (timeOutEvent != 0) {
            //这里写要执行的内容（尤如onclick事件）
            // alert("你这是点击，不是长按");
        }
        return false;
    };
    //如果手指有移动，则取消所有事件，此时说明用户只是要移动而不是长按
    function gtouchmove() {
        clearTimeout(timeOutEvent); //清除定时器
        timeOutEvent = 0;
    };

    //真正长按后应该执行的内容
    function longPress() {
        if(vm.isSelectAddress) {
            return;
        }
        timeOutEvent = 0;
        var list = deepCopy(vm.listData);
        list[longIndex].sel = true;
        vm.listData = list;
    }

    function editFn(item) {
        fnOpenPublicWin('编辑收货信息', 'teacher/edit_address', {
            item: item,
            winName: api.winName,
            frmName: api.frameName
        })
    }

    function deleteFn(item) {
        var url = 'common/deleteById';
        var params = {
            "entityName": 'umsMemberReceiveAddress',
            "id": item.id
        };
        var callback = function (data) {
            fnToast("删除成功");
            getPageData('headerRefreshing');
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }

    function setDefault(item) {
        var url = 'common/updateById';
        var params = {
            "entityName": 'umsMemberReceiveAddress',
            "id": item.id,
            "defaultStatus": '1',
            "isDefault": '1'
        };
        var callback = function (data) {
            fnToast("设置成功");
            getPageData('headerRefreshing');
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }

    document.body.addEventListener('click', function () {
        vm.listData = setPropertyInArray(vm.listData, 'sel', false);
    }, false)
</script>

</html>